
package com.yuan.servlet;

import com.yuan.hibernate.员工信息表;
import com.yuan.hibernate.员工信息表DAO;
import com.yuan.hibernate.请假申请;
import com.yuan.hibernate.请假申请DAO;
import com.yuan.util.TimeUtil;

import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class askleaveservlet extends BaseHttpServlet {

    private 请假申请DAO m请假申请DAO = null;
    private 请假申请 m请假申请 = null;
    private 员工信息表DAO m员工信息表DAO = null;
    private 员工信息表 m员工信息表 = null;
    private SimpleDateFormat format = null;
    private Date d1, d2;
    private long HM = 0;
    private List<?> list = null;

    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        super.doGet(request, response);
        int userid = Integer.parseInt(request.getParameter("userid"));
        String leavetype = new String(request.getParameter("leavetype").getBytes("ISO-8859-1"),
                "UTF-8");
        String starttime = request.getParameter("starttime");
        String endtime = request.getParameter("endtime");
        String reason = new String(request.getParameter("reason").getBytes("ISO-8859-1"), "UTF-8");
        format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            d1 = format.parse(starttime); // 读取文本框中输入的字符串，并将其转化为日期格式
            d2 = format.parse(endtime);
            HM = d2.getTime() - d1.getTime();
            HM = (long) (HM / (1000 * 60 * 60));
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        m请假申请DAO = new 请假申请DAO();
        m员工信息表DAO = new 员工信息表DAO();
        m员工信息表 = m员工信息表DAO.findById(userid);
        m请假申请 = new 请假申请();
        m请假申请.set填表人("管理员");
        m请假申请.set申请人(userid + "");
        m请假申请.set姓名(m员工信息表.get姓名());
        m请假申请.set所属队室(m员工信息表.get所属队室());
        m请假申请.set请假类别(leavetype);
        m请假申请.set开始(starttime);
        m请假申请.set结束(endtime);
        m请假申请.set总时间((float) HM);
        m请假申请.set请假理由(reason);
        m请假申请.set意见("<hr>审批意见如下：");
        m请假申请.setWillread("管理员");
        m请假申请.set申请日期(TimeUtil.getNowTime());
        m请假申请DAO.save(m请假申请);
        list = m请假申请DAO.findByExample(m请假申请);
        mResponse = com.yuan.util.JsonUtils.getFromList(list);
        closeAndClear();
    }

    protected synchronized void closeAndClear() {
        m请假申请DAO = null;
        m请假申请 = null;
        m员工信息表DAO = null;
        m员工信息表 = null;
        format = null;
        list = null;
        super.closeAndClear();
    }
}
